import 'package:flutter/material.dart';
import 'package:flutter_widgets_pc/widgets/bottomSheet/kq_botton_sheet_manger.dart';
import 'package:flutter_widgets_pc/widgets/bottomSheet/sheets/kq_action_list_bottom_sheet.dart';
import '../../utils/native/file_picker_native_util.dart';

class KqUpload {
  int maxCount;
  KqUpload({this.maxCount = 1});

  //上传
  void handleUpload(
      BuildContext context, Function(List<KqFile> file)? callBack) {
    KqBottomSheetManager.showActionList(
      [KqActionListData(item: '相机拍照'), KqActionListData(item: '相册选图')],
      callback: ((index, item) async {
        if (index == 1) {
          //相册
          var files = await FilePickerNativeUtil.pickImages(maxCount: maxCount);
          if (callBack != null) {
            callBack(files);
          }
        } else {
          //拍照
          var file = await FilePickerNativeUtil.takePhoto();
          if (callBack != null) {
            callBack(file != null ? [file] : []);
          }
        }
      }),
      showCancel: true,
    );
  }
}
